package statistics;

import junit.framework.TestCase;
import numerics.Pair;
import numerics.linreg;


public class Testlinreg extends TestCase {
	// Teste 1 r
	public void testr1(){
		Pair[] pairs = new Pair[10];
		
		pairs[0] = new Pair(130, 186);
		pairs[1] = new Pair(650, 699);
		pairs[2] = new Pair(99, 132);
		pairs[3] = new Pair(150, 272);
		pairs[4] = new Pair(128, 291);
		pairs[5] = new Pair(302, 331);
		pairs[6] = new Pair(95, 199);
		pairs[7] = new Pair(945, 1890);
		pairs[8] = new Pair(368, 788);
		pairs[9] = new Pair(961, 1601);	
		
		assertEquals(0.9545, linreg.r(pairs), 0.5E-5);
	}
	// Teste 2 r
	public void testr2(){
		Pair[] pairs2 = new Pair[10];
		
		pairs2[0] = new Pair(130, 15.0);
		pairs2[1] = new Pair(650, 69.9);
		pairs2[2] = new Pair(99, 6.5);
		pairs2[3] = new Pair(150, 22.4);
		pairs2[4] = new Pair(128, 28.4);
		pairs2[5] = new Pair(302, 65.9);
		pairs2[6] = new Pair(95, 19.4);
		pairs2[7] = new Pair(945, 198.7);
		pairs2[8] = new Pair(368, 38.8);
		pairs2[9] = new Pair(961, 138.2);
		
		assertEquals(0.933306, linreg.r(pairs2), 0.5E-5);
	}
	
	// Teste Beta0 1 
	public void testBeta01(){
		Pair[] pairs = new Pair[10];
		
		pairs[0] = new Pair(130, 186);
		pairs[1] = new Pair(650, 699);
		pairs[2] = new Pair(99, 132);
		pairs[3] = new Pair(150, 272);
		pairs[4] = new Pair(128, 291);
		pairs[5] = new Pair(302, 331);
		pairs[6] = new Pair(95, 199);
		pairs[7] = new Pair(945, 1890);
		pairs[8] = new Pair(368, 788);
		pairs[9] = new Pair(961, 1601);	
		
		assertEquals(-22.55, linreg.Beta0(pairs), 0.5E-2);
	}
	// Teste Beta0 2
	public void testBeta02(){
		Pair[] pairs2 = new Pair[10];
		
		pairs2[0] = new Pair(130, 15.0);
		pairs2[1] = new Pair(650, 69.9);
		pairs2[2] = new Pair(99, 6.5);
		pairs2[3] = new Pair(150, 22.4);
		pairs2[4] = new Pair(128, 28.4);
		pairs2[5] = new Pair(302, 65.9);
		pairs2[6] = new Pair(95, 19.4);
		pairs2[7] = new Pair(945, 198.7);
		pairs2[8] = new Pair(368, 38.8);
		pairs2[9] = new Pair(961, 138.2);
		
		assertEquals(-4.039, linreg.Beta0(pairs2), 0.5E-2);
	}
	
	// Teste Beta1 1 
	public void testBeta11(){
		Pair[] pairs = new Pair[10];
		
		pairs[0] = new Pair(130, 186);
		pairs[1] = new Pair(650, 699);
		pairs[2] = new Pair(99, 132);
		pairs[3] = new Pair(150, 272);
		pairs[4] = new Pair(128, 291);
		pairs[5] = new Pair(302, 331);
		pairs[6] = new Pair(95, 199);
		pairs[7] = new Pair(945, 1890);
		pairs[8] = new Pair(368, 788);
		pairs[9] = new Pair(961, 1601);	
		
		assertEquals(1.728, linreg.Beta1(pairs), 0.5E-2);
	}
	// Teste Beta1 2
	public void testBeta12(){
		Pair[] pairs2 = new Pair[10];
		
		pairs2[0] = new Pair(130, 15.0);
		pairs2[1] = new Pair(650, 69.9);
		pairs2[2] = new Pair(99, 6.5);
		pairs2[3] = new Pair(150, 22.4);
		pairs2[4] = new Pair(128, 28.4);
		pairs2[5] = new Pair(302, 65.9);
		pairs2[6] = new Pair(95, 19.4);
		pairs2[7] = new Pair(945, 198.7);
		pairs2[8] = new Pair(368, 38.8);
		pairs2[9] = new Pair(961, 138.2);
		
		assertEquals(0.1681, linreg.Beta1(pairs2), 0.5E-2);
	}	
	
	// Teste tail 1
	public void testtailArea1(){
		assertEquals(1.77E-05, linreg.tailArea(0.9545,10), 0.5E-5);
	}
	// Teste tail 2
	public void testtailArea2(){
		assertEquals(1.77E-05, linreg.tailArea(0.9333,10), 0.5E-5);
	}	
}
